
<!doctype html>
<html lang="zh" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
        <meta name="description" content="脚本文档">
      
      
        <meta name="author" content="Logan">
      
      
        <link rel="canonical" href="http://localhost:8000/installation/message_queue_services/">
      
      
        <link rel="prev" href="../logging_services/">
      
      
        <link rel="next" href="../storage/">
      
      
      <link rel="icon" href="../../image/favicon.ico">
      <meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.5.50">
    
    
      
        <title>消息队列 - 运维无忧文档</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.a40c8224.min.css">
      
        
        <link rel="stylesheet" href="../../assets/stylesheets/palette.06af60db.min.css">
      
      


    
    
      
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../../css/extra.css">
    
      <link rel="stylesheet" href="../../css/prism.css">
    
    <script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="blue">
  
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#_1" class="md-skip">
          跳转至
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

  

<header class="md-header md-header--shadow" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="页眉">
    <a href="../.." title="运维无忧文档" class="md-header__button md-logo" aria-label="运维无忧文档" data-md-component="logo">
      
  <img src="../../image/logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            运维无忧文档
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              消息队列
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
  
    
    
    
    <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="blue"  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_0">
    
      <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 7a5 5 0 0 1 5 5 5 5 0 0 1-5 5 5 5 0 0 1-5-5 5 5 0 0 1 5-5m0 2a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0-7 2.39 3.42C13.65 5.15 12.84 5 12 5s-1.65.15-2.39.42zM3.34 7l4.16-.35A7.2 7.2 0 0 0 5.94 8.5c-.44.74-.69 1.5-.83 2.29zm.02 10 1.76-3.77a7.131 7.131 0 0 0 2.38 4.14zM20.65 7l-1.77 3.79a7.02 7.02 0 0 0-2.38-4.15zm-.01 10-4.14.36c.59-.51 1.12-1.14 1.54-1.86.42-.73.69-1.5.83-2.29zM12 22l-2.41-3.44c.74.27 1.55.44 2.41.44.82 0 1.63-.17 2.37-.44z"/></svg>
      </label>
    
  
    
    
    
    <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="blue"  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_1">
    
      <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m17.75 4.09-2.53 1.94.91 3.06-2.63-1.81-2.63 1.81.91-3.06-2.53-1.94L12.44 4l1.06-3 1.06 3zm3.5 6.91-1.64 1.25.59 1.98-1.7-1.17-1.7 1.17.59-1.98L15.75 11l2.06-.05L18.5 9l.69 1.95zm-2.28 4.95c.83-.08 1.72 1.1 1.19 1.85-.32.45-.66.87-1.08 1.27C15.17 23 8.84 23 4.94 19.07c-3.91-3.9-3.91-10.24 0-14.14.4-.4.82-.76 1.27-1.08.75-.53 1.93.36 1.85 1.19-.27 2.86.69 5.83 2.89 8.02a9.96 9.96 0 0 0 8.02 2.89m-1.64 2.02a12.08 12.08 0 0 1-7.8-3.47c-2.17-2.19-3.33-5-3.49-7.82-2.81 3.14-2.7 7.96.31 10.98 3.02 3.01 7.84 3.12 10.98.31"/></svg>
      </label>
    
  
</form>
      
    
    
      <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
    
    
    
      <label class="md-header__button md-icon" for="__search">
        
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
        
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="查找">
        
        <button type="reset" class="md-search__icon md-icon" title="清空当前内容" aria-label="清空当前内容" tabindex="-1">
          
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
        </button>
      </nav>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            正在初始化搜索引擎
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://git.opsx.vip/docs/wuyou.run.git" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
  </div>
  <div class="md-source__repository">
    wuyou.run
  </div>
</a>
      </div>
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    



<nav class="md-nav md-nav--primary" aria-label="导航栏" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../.." title="运维无忧文档" class="md-nav__button md-logo" aria-label="运维无忧文档" data-md-component="logo">
      
  <img src="../../image/logo.png" alt="logo">

    </a>
    运维无忧文档
  </label>
  
    <div class="md-nav__source">
      <a href="https://git.opsx.vip/docs/wuyou.run.git" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
  </div>
  <div class="md-source__repository">
    wuyou.run
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../.." class="md-nav__link">
        
  
  <span class="md-ellipsis">
    首页
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
    
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" checked>
        
          
          <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    Linux基础设施
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="true">
          <label class="md-nav__title" for="__nav_2">
            <span class="md-nav__icon md-icon"></span>
            Linux基础设施
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_1" >
        
          
          <label class="md-nav__link" for="__nav_2_1" id="__nav_2_1_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    基础环境配置
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_1_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_2_1">
            <span class="md-nav__icon md-icon"></span>
            基础环境配置
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../system_init/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    系统初始化
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../dev_env/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    开发环境搭建
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
    
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_2" checked>
        
          
          <label class="md-nav__link" for="__nav_2_2" id="__nav_2_2_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    常用服务部署
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_2_label" aria-expanded="true">
          <label class="md-nav__title" for="__nav_2_2">
            <span class="md-nav__icon md-icon"></span>
            常用服务部署
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_2_1" >
        
          
          <label class="md-nav__link" for="__nav_2_2_1" id="__nav_2_2_1_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    Web服务与代理
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="3" aria-labelledby="__nav_2_2_1_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_2_2_1">
            <span class="md-nav__icon md-icon"></span>
            Web服务与代理
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../web_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Web服务
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../proxy_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    代理服务
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../services-loadbalancing/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    负载均衡服务
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../cache_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    缓存加速服务
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_2_2" >
        
          
          <label class="md-nav__link" for="__nav_2_2_2" id="__nav_2_2_2_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    数据存储
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="3" aria-labelledby="__nav_2_2_2_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_2_2_2">
            <span class="md-nav__icon md-icon"></span>
            数据存储
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../database_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    数据库服务
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../storage_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    文件存储服务
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_2_3" >
        
          
          <label class="md-nav__link" for="__nav_2_2_3" id="__nav_2_2_3_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    监控与日志
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="3" aria-labelledby="__nav_2_2_3_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_2_2_3">
            <span class="md-nav__icon md-icon"></span>
            监控与日志
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../monitoring_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    监控系统
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../logging_services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    日志管理
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
    
  
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
        
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          
  
  <span class="md-ellipsis">
    消息队列
  </span>
  

          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="./" class="md-nav__link md-nav__link--active">
        
  
  <span class="md-ellipsis">
    消息队列
  </span>
  

      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      目录
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    <span class="md-ellipsis">
      概述
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#rabbitmq" class="md-nav__link">
    <span class="md-ellipsis">
      RabbitMQ部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="RabbitMQ部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    <span class="md-ellipsis">
      单节点安装
    </span>
  </a>
  
    <nav class="md-nav" aria-label="单节点安装">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_4" class="md-nav__link">
    <span class="md-ellipsis">
      安装依赖
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_1" class="md-nav__link">
    <span class="md-ellipsis">
      安装RabbitMQ
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_2" class="md-nav__link">
    <span class="md-ellipsis">
      配置RabbitMQ
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_3" class="md-nav__link">
    <span class="md-ellipsis">
      启动RabbitMQ服务
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_5" class="md-nav__link">
    <span class="md-ellipsis">
      验证安装
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_6" class="md-nav__link">
    <span class="md-ellipsis">
      集群部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="集群部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_7" class="md-nav__link">
    <span class="md-ellipsis">
      准备工作
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#erlang-cookie" class="md-nav__link">
    <span class="md-ellipsis">
      设置Erlang Cookie
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_8" class="md-nav__link">
    <span class="md-ellipsis">
      配置集群
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_9" class="md-nav__link">
    <span class="md-ellipsis">
      配置镜像队列
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_10" class="md-nav__link">
    <span class="md-ellipsis">
      常见管理操作
    </span>
  </a>
  
    <nav class="md-nav" aria-label="常见管理操作">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_11" class="md-nav__link">
    <span class="md-ellipsis">
      用户管理
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_12" class="md-nav__link">
    <span class="md-ellipsis">
      虚拟主机管理
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_13" class="md-nav__link">
    <span class="md-ellipsis">
      队列和交换机管理
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_14" class="md-nav__link">
    <span class="md-ellipsis">
      安全配置
    </span>
  </a>
  
    <nav class="md-nav" aria-label="安全配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#ssltls" class="md-nav__link">
    <span class="md-ellipsis">
      SSL/TLS配置
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_15" class="md-nav__link">
    <span class="md-ellipsis">
      性能调优
    </span>
  </a>
  
    <nav class="md-nav" aria-label="性能调优">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_16" class="md-nav__link">
    <span class="md-ellipsis">
      系统优化
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_4" class="md-nav__link">
    <span class="md-ellipsis">
      RabbitMQ 监控
    </span>
  </a>
  
    <nav class="md-nav" aria-label="RabbitMQ 监控">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#prometheus" class="md-nav__link">
    <span class="md-ellipsis">
      启用Prometheus插件
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_17" class="md-nav__link">
    <span class="md-ellipsis">
      设置告警
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#apache-kafka" class="md-nav__link">
    <span class="md-ellipsis">
      Apache Kafka部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="Apache Kafka部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_18" class="md-nav__link">
    <span class="md-ellipsis">
      单节点安装
    </span>
  </a>
  
    <nav class="md-nav" aria-label="单节点安装">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#java" class="md-nav__link">
    <span class="md-ellipsis">
      安装Java
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka" class="md-nav__link">
    <span class="md-ellipsis">
      下载和安装Kafka
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_1" class="md-nav__link">
    <span class="md-ellipsis">
      配置Kafka
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#systemd" class="md-nav__link">
    <span class="md-ellipsis">
      创建Systemd服务
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_2" class="md-nav__link">
    <span class="md-ellipsis">
      启动Kafka服务
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_19" class="md-nav__link">
    <span class="md-ellipsis">
      集群部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="集群部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_20" class="md-nav__link">
    <span class="md-ellipsis">
      准备工作
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#zookeeper" class="md-nav__link">
    <span class="md-ellipsis">
      配置ZooKeeper集群
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_3" class="md-nav__link">
    <span class="md-ellipsis">
      配置Kafka集群
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_21" class="md-nav__link">
    <span class="md-ellipsis">
      启动集群
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_22" class="md-nav__link">
    <span class="md-ellipsis">
      常见管理操作
    </span>
  </a>
  
    <nav class="md-nav" aria-label="常见管理操作">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_23" class="md-nav__link">
    <span class="md-ellipsis">
      主题管理
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_24" class="md-nav__link">
    <span class="md-ellipsis">
      消息生产和消费
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_25" class="md-nav__link">
    <span class="md-ellipsis">
      消费者组管理
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_26" class="md-nav__link">
    <span class="md-ellipsis">
      安全配置
    </span>
  </a>
  
    <nav class="md-nav" aria-label="安全配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#saslscram" class="md-nav__link">
    <span class="md-ellipsis">
      SASL/SCRAM认证
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_4" class="md-nav__link">
    <span class="md-ellipsis">
      监控Kafka
    </span>
  </a>
  
    <nav class="md-nav" aria-label="监控Kafka">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#jmxprometheus" class="md-nav__link">
    <span class="md-ellipsis">
      使用JMX和Prometheus
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#redis-pubsub" class="md-nav__link">
    <span class="md-ellipsis">
      Redis Pub/Sub
    </span>
  </a>
  
    <nav class="md-nav" aria-label="Redis Pub/Sub">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#redis" class="md-nav__link">
    <span class="md-ellipsis">
      Redis 安装与配置
    </span>
  </a>
  
    <nav class="md-nav" aria-label="Redis 安装与配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#redis_1" class="md-nav__link">
    <span class="md-ellipsis">
      安装Redis
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#redis_2" class="md-nav__link">
    <span class="md-ellipsis">
      配置Redis
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#redis_3" class="md-nav__link">
    <span class="md-ellipsis">
      启动Redis服务
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#redis-pubsub_1" class="md-nav__link">
    <span class="md-ellipsis">
      使用Redis Pub/Sub
    </span>
  </a>
  
    <nav class="md-nav" aria-label="使用Redis Pub/Sub">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_27" class="md-nav__link">
    <span class="md-ellipsis">
      基本命令
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_28" class="md-nav__link">
    <span class="md-ellipsis">
      消息持久化
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_29" class="md-nav__link">
    <span class="md-ellipsis">
      客户端示例
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_30" class="md-nav__link">
    <span class="md-ellipsis">
      后续章节
    </span>
  </a>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_3" >
        
          
          <label class="md-nav__link" for="__nav_2_3" id="__nav_2_3_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    系统运维
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_3_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_2_3">
            <span class="md-nav__icon md-icon"></span>
            系统运维
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../storage/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    存储与备份
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../lvm/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    LVM存储管理
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../network/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    网络服务配置
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../monitor/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    监控与日志
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
      
      
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
        
          
          <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    容器与编排
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_3">
            <span class="md-nav__icon md-icon"></span>
            容器与编排
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_1" >
        
          
          <label class="md-nav__link" for="__nav_3_1" id="__nav_3_1_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    Docker
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_1_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_3_1">
            <span class="md-nav__icon md-icon"></span>
            Docker
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../docker/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    基础安装
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../docker/build/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    镜像构建
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../docker/services/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    常用服务部署
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../docker/network-storage/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    网络与存储
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../docker-compose/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Docker Compose
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_3" >
        
          
          <label class="md-nav__link" for="__nav_3_3" id="__nav_3_3_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    Kubernetes
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_3_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_3_3">
            <span class="md-nav__icon md-icon"></span>
            Kubernetes
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../kubernetes/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    集群部署
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../kubernetes/resources/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    资源管理
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../kubernetes/operations/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    运维操作
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../kubernetes/best-practices/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    最佳实践
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
      
      
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
        
          
          <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    DevOps工具链
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_4">
            <span class="md-nav__icon md-icon"></span>
            DevOps工具链
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../cicd/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    CI/CD流水线
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../devops/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    自动化运维
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
      
      
  
  
  
  
    
    
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
        
          
          <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    Shell 快速入门
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_5">
            <span class="md-nav__icon md-icon"></span>
            Shell 快速入门
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/introduction/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Linux 基础命令
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/commands/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    常用命令集
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/variables_and_data_types/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    变量和数据类型
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/control_flow/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    控制流程 (if、else、for、while)
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/functions/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Shell函数
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/text_processing/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    文本处理三剑客
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../shell/scripts/" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Shell脚本实战
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      目录
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    <span class="md-ellipsis">
      概述
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#rabbitmq" class="md-nav__link">
    <span class="md-ellipsis">
      RabbitMQ部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="RabbitMQ部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    <span class="md-ellipsis">
      单节点安装
    </span>
  </a>
  
    <nav class="md-nav" aria-label="单节点安装">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_4" class="md-nav__link">
    <span class="md-ellipsis">
      安装依赖
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_1" class="md-nav__link">
    <span class="md-ellipsis">
      安装RabbitMQ
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_2" class="md-nav__link">
    <span class="md-ellipsis">
      配置RabbitMQ
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_3" class="md-nav__link">
    <span class="md-ellipsis">
      启动RabbitMQ服务
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_5" class="md-nav__link">
    <span class="md-ellipsis">
      验证安装
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_6" class="md-nav__link">
    <span class="md-ellipsis">
      集群部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="集群部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_7" class="md-nav__link">
    <span class="md-ellipsis">
      准备工作
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#erlang-cookie" class="md-nav__link">
    <span class="md-ellipsis">
      设置Erlang Cookie
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_8" class="md-nav__link">
    <span class="md-ellipsis">
      配置集群
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_9" class="md-nav__link">
    <span class="md-ellipsis">
      配置镜像队列
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_10" class="md-nav__link">
    <span class="md-ellipsis">
      常见管理操作
    </span>
  </a>
  
    <nav class="md-nav" aria-label="常见管理操作">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_11" class="md-nav__link">
    <span class="md-ellipsis">
      用户管理
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_12" class="md-nav__link">
    <span class="md-ellipsis">
      虚拟主机管理
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_13" class="md-nav__link">
    <span class="md-ellipsis">
      队列和交换机管理
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_14" class="md-nav__link">
    <span class="md-ellipsis">
      安全配置
    </span>
  </a>
  
    <nav class="md-nav" aria-label="安全配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#ssltls" class="md-nav__link">
    <span class="md-ellipsis">
      SSL/TLS配置
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_15" class="md-nav__link">
    <span class="md-ellipsis">
      性能调优
    </span>
  </a>
  
    <nav class="md-nav" aria-label="性能调优">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_16" class="md-nav__link">
    <span class="md-ellipsis">
      系统优化
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#rabbitmq_4" class="md-nav__link">
    <span class="md-ellipsis">
      RabbitMQ 监控
    </span>
  </a>
  
    <nav class="md-nav" aria-label="RabbitMQ 监控">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#prometheus" class="md-nav__link">
    <span class="md-ellipsis">
      启用Prometheus插件
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_17" class="md-nav__link">
    <span class="md-ellipsis">
      设置告警
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#apache-kafka" class="md-nav__link">
    <span class="md-ellipsis">
      Apache Kafka部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="Apache Kafka部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_18" class="md-nav__link">
    <span class="md-ellipsis">
      单节点安装
    </span>
  </a>
  
    <nav class="md-nav" aria-label="单节点安装">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#java" class="md-nav__link">
    <span class="md-ellipsis">
      安装Java
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka" class="md-nav__link">
    <span class="md-ellipsis">
      下载和安装Kafka
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_1" class="md-nav__link">
    <span class="md-ellipsis">
      配置Kafka
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#systemd" class="md-nav__link">
    <span class="md-ellipsis">
      创建Systemd服务
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_2" class="md-nav__link">
    <span class="md-ellipsis">
      启动Kafka服务
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_19" class="md-nav__link">
    <span class="md-ellipsis">
      集群部署
    </span>
  </a>
  
    <nav class="md-nav" aria-label="集群部署">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_20" class="md-nav__link">
    <span class="md-ellipsis">
      准备工作
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#zookeeper" class="md-nav__link">
    <span class="md-ellipsis">
      配置ZooKeeper集群
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_3" class="md-nav__link">
    <span class="md-ellipsis">
      配置Kafka集群
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_21" class="md-nav__link">
    <span class="md-ellipsis">
      启动集群
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_22" class="md-nav__link">
    <span class="md-ellipsis">
      常见管理操作
    </span>
  </a>
  
    <nav class="md-nav" aria-label="常见管理操作">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_23" class="md-nav__link">
    <span class="md-ellipsis">
      主题管理
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_24" class="md-nav__link">
    <span class="md-ellipsis">
      消息生产和消费
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_25" class="md-nav__link">
    <span class="md-ellipsis">
      消费者组管理
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_26" class="md-nav__link">
    <span class="md-ellipsis">
      安全配置
    </span>
  </a>
  
    <nav class="md-nav" aria-label="安全配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#saslscram" class="md-nav__link">
    <span class="md-ellipsis">
      SASL/SCRAM认证
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#kafka_4" class="md-nav__link">
    <span class="md-ellipsis">
      监控Kafka
    </span>
  </a>
  
    <nav class="md-nav" aria-label="监控Kafka">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#jmxprometheus" class="md-nav__link">
    <span class="md-ellipsis">
      使用JMX和Prometheus
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#redis-pubsub" class="md-nav__link">
    <span class="md-ellipsis">
      Redis Pub/Sub
    </span>
  </a>
  
    <nav class="md-nav" aria-label="Redis Pub/Sub">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#redis" class="md-nav__link">
    <span class="md-ellipsis">
      Redis 安装与配置
    </span>
  </a>
  
    <nav class="md-nav" aria-label="Redis 安装与配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#redis_1" class="md-nav__link">
    <span class="md-ellipsis">
      安装Redis
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#redis_2" class="md-nav__link">
    <span class="md-ellipsis">
      配置Redis
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#redis_3" class="md-nav__link">
    <span class="md-ellipsis">
      启动Redis服务
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
          <li class="md-nav__item">
  <a href="#redis-pubsub_1" class="md-nav__link">
    <span class="md-ellipsis">
      使用Redis Pub/Sub
    </span>
  </a>
  
    <nav class="md-nav" aria-label="使用Redis Pub/Sub">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_27" class="md-nav__link">
    <span class="md-ellipsis">
      基本命令
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_28" class="md-nav__link">
    <span class="md-ellipsis">
      消息持久化
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_29" class="md-nav__link">
    <span class="md-ellipsis">
      客户端示例
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_30" class="md-nav__link">
    <span class="md-ellipsis">
      后续章节
    </span>
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  

  
  


<h1 id="_1">消息队列与中间件部署指南</h1>
<p>@author Loganli</p>
<h2 id="_2">概述</h2>
<p>消息队列和中间件系统是构建分布式系统和微服务架构的重要组件，它们提供了可靠的消息传递、解耦、异步处理和负载均衡等核心功能。本文档涵盖了以下主要消息队列和中间件系统的部署与配置：</p>
<ul>
<li>RabbitMQ：高可靠性的消息队列系统</li>
<li>Apache Kafka：高吞吐量的分布式流处理平台</li>
<li>Redis Pub/Sub：轻量级消息发布/订阅系统</li>
<li>ActiveMQ：功能丰富的开源消息代理</li>
<li>ZeroMQ：轻量级的消息库</li>
</ul>
<h2 id="rabbitmq">RabbitMQ部署</h2>
<h3 id="_3">单节点安装</h3>
<h4 id="_4">安装依赖</h4>
<pre><code class="language-bash"># CentOS/RHEL
yum install -y epel-release
yum install -y erlang socat logrotate

# Debian/Ubuntu
apt-get update
apt-get install -y erlang socat logrotate
</code></pre>
<h4 id="rabbitmq_1">安装RabbitMQ</h4>
<pre><code class="language-bash"># CentOS/RHEL (使用RabbitMQ官方仓库)
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | bash
yum install -y rabbitmq-server

# Debian/Ubuntu (使用RabbitMQ官方仓库)
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash
apt-get update
apt-get install -y rabbitmq-server
</code></pre>
<h4 id="rabbitmq_2">配置RabbitMQ</h4>
<p>创建配置文件 <code>/etc/rabbitmq/rabbitmq.conf</code>:</p>
<pre><code># 网络和端口设置
listeners.tcp.default = 5672
management.tcp.port = 15672

# 内存和磁盘阈值
vm_memory_high_watermark.relative = 0.7
disk_free_limit.absolute = 2GB

# 默认用户和密码访问控制
default_user = guest
default_pass = guest
default_permissions.configure = .*
default_permissions.read = .*
default_permissions.write = .*
default_user_tags.administrator = true

# 默认只允许本地访问，修改为允许远程访问
loopback_users = none

# 集群和节点名称
cluster_name = rabbitmq-cluster
</code></pre>
<h4 id="rabbitmq_3">启动RabbitMQ服务</h4>
<pre><code class="language-bash"># 启动服务
systemctl start rabbitmq-server
systemctl enable rabbitmq-server
systemctl status rabbitmq-server

# 启用管理插件
rabbitmq-plugins enable rabbitmq_management

# 创建管理员用户(替换默认guest)
rabbitmqctl add_user admin StrongPassword
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin &quot;.*&quot; &quot;.*&quot; &quot;.*&quot;

# 删除默认guest用户(可选但推荐)
rabbitmqctl delete_user guest
</code></pre>
<h4 id="_5">验证安装</h4>
<p>访问Web管理界面：http://server_ip:15672/
使用刚创建的admin用户登录</p>
<h3 id="_6">集群部署</h3>
<h4 id="_7">准备工作</h4>
<p>在所有节点上完成单节点安装后，确保：</p>
<ol>
<li>所有节点可以通过主机名互相访问</li>
<li>所有节点的 Erlang cookie 相同</li>
</ol>
<h4 id="erlang-cookie">设置Erlang Cookie</h4>
<p>在所有节点上执行：</p>
<pre><code class="language-bash"># 停止RabbitMQ
systemctl stop rabbitmq-server

# 设置相同的Erlang Cookie
echo 'RABBITMQ-CLUSTER-COOKIE' &gt; /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

# 重启服务
systemctl start rabbitmq-server
</code></pre>
<h4 id="_8">配置集群</h4>
<p>在第一个节点(rabbit1)上：</p>
<pre><code class="language-bash"># 不需要特殊操作，作为第一个节点
</code></pre>
<p>在其他节点(rabbit2, rabbit3, ...)上：</p>
<pre><code class="language-bash"># 停止RabbitMQ应用程序
rabbitmqctl stop_app

# 重置节点
rabbitmqctl reset

# 加入集群(将rabbit1替换为第一个节点的主机名)
rabbitmqctl join_cluster rabbit@rabbit1

# 启动应用程序
rabbitmqctl start_app

# 验证集群状态
rabbitmqctl cluster_status
</code></pre>
<h4 id="_9">配置镜像队列</h4>
<p>在任一节点上设置镜像队列策略：</p>
<pre><code class="language-bash"># 所有队列镜像到所有节点
rabbitmqctl set_policy ha-all &quot;.*&quot; '{&quot;ha-mode&quot;:&quot;all&quot;}' --apply-to queues
</code></pre>
<h3 id="_10">常见管理操作</h3>
<h4 id="_11">用户管理</h4>
<pre><code class="language-bash"># 创建用户
rabbitmqctl add_user username password

# 设置角色
rabbitmqctl set_user_tags username administrator

# 设置权限
rabbitmqctl set_permissions -p / username &quot;.*&quot; &quot;.*&quot; &quot;.*&quot;

# 列出所有用户
rabbitmqctl list_users

# 删除用户
rabbitmqctl delete_user username
</code></pre>
<h4 id="_12">虚拟主机管理</h4>
<pre><code class="language-bash"># 创建虚拟主机
rabbitmqctl add_vhost my_vhost

# 列出所有虚拟主机
rabbitmqctl list_vhosts

# 设置用户对虚拟主机的权限
rabbitmqctl set_permissions -p my_vhost username &quot;.*&quot; &quot;.*&quot; &quot;.*&quot;

# 删除虚拟主机
rabbitmqctl delete_vhost my_vhost
</code></pre>
<h4 id="_13">队列和交换机管理</h4>
<p>通过Web管理界面或使用rabbitmqadmin命令：</p>
<pre><code class="language-bash"># 安装rabbitmqadmin
wget http://localhost:15672/cli/rabbitmqadmin -O /usr/local/bin/rabbitmqadmin
chmod +x /usr/local/bin/rabbitmqadmin

# 列出队列
rabbitmqadmin list queues

# 列出交换机
rabbitmqadmin list exchanges

# 创建队列
rabbitmqadmin declare queue name=my_queue durable=true

# 发布消息
rabbitmqadmin publish exchange=amq.default routing_key=my_queue payload=&quot;hello, world&quot;

# 获取消息
rabbitmqadmin get queue=my_queue count=1
</code></pre>
<h3 id="_14">安全配置</h3>
<h4 id="ssltls">SSL/TLS配置</h4>
<p>生成SSL证书：</p>
<pre><code class="language-bash"># 创建证书目录
mkdir -p /etc/rabbitmq/ssl

# 生成CA密钥和证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/rabbitmq/ssl/ca.key -out /etc/rabbitmq/ssl/ca.crt

# 生成服务器密钥和证书签名请求
openssl req -nodes -newkey rsa:2048 -keyout /etc/rabbitmq/ssl/server.key -out /etc/rabbitmq/ssl/server.csr

# 使用CA签署服务器证书
openssl x509 -req -days 365 -in /etc/rabbitmq/ssl/server.csr -CA /etc/rabbitmq/ssl/ca.crt -CAkey /etc/rabbitmq/ssl/ca.key -CAcreateserial -out /etc/rabbitmq/ssl/server.crt

# 设置权限
chown -R rabbitmq:rabbitmq /etc/rabbitmq/ssl
chmod -R 500 /etc/rabbitmq/ssl
chmod 400 /etc/rabbitmq/ssl/*
</code></pre>
<p>配置RabbitMQ使用SSL，在<code>/etc/rabbitmq/rabbitmq.conf</code>中添加：</p>
<pre><code>listeners.ssl.default = 5671
ssl_options.cacertfile = /etc/rabbitmq/ssl/ca.crt
ssl_options.certfile = /etc/rabbitmq/ssl/server.crt
ssl_options.keyfile = /etc/rabbitmq/ssl/server.key
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = false
</code></pre>
<h3 id="_15">性能调优</h3>
<h4 id="_16">系统优化</h4>
<p>在<code>/etc/sysctl.conf</code>中添加：</p>
<pre><code># 文件描述符限制
fs.file-max = 100000

# 网络设置
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
</code></pre>
<p>应用更改：</p>
<pre><code class="language-bash">sysctl -p
</code></pre>
<p>在<code>/etc/security/limits.conf</code>中添加：</p>
<pre><code>rabbitmq soft nofile 65536
rabbitmq hard nofile 65536
</code></pre>
<h3 id="rabbitmq_4">RabbitMQ 监控</h3>
<h4 id="prometheus">启用Prometheus插件</h4>
<pre><code class="language-bash">rabbitmq-plugins enable rabbitmq_prometheus

# 如果使用Grafana，可以导入RabbitMQ的仪表板模板
</code></pre>
<h4 id="_17">设置告警</h4>
<p>使用RabbitMQ管理插件的告警功能或集成Prometheus + Alertmanager。</p>
<h2 id="apache-kafka">Apache Kafka部署</h2>
<h3 id="_18">单节点安装</h3>
<h4 id="java">安装Java</h4>
<pre><code class="language-bash"># CentOS/RHEL
yum install -y java-11-openjdk-devel

# Debian/Ubuntu
apt-get update
apt-get install -y openjdk-11-jdk
</code></pre>
<h4 id="kafka">下载和安装Kafka</h4>
<pre><code class="language-bash"># 创建安装目录
mkdir -p /opt/kafka
cd /opt/kafka

# 下载Kafka
wget https://downloads.apache.org/kafka/3.1.0/kafka_2.13-3.1.0.tgz
tar -xzf kafka_2.13-3.1.0.tgz --strip 1
rm kafka_2.13-3.1.0.tgz
</code></pre>
<h4 id="kafka_1">配置Kafka</h4>
<p>编辑<code>/opt/kafka/config/server.properties</code>：</p>
<pre><code class="language-properties"># 基本设置
broker.id=0
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://your_server_ip:9092
num.network.threads=3
num.io.threads=8

# 日志设置
log.dirs=/var/lib/kafka/logs
num.partitions=3
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000

# ZooKeeper设置
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=18000
</code></pre>
<p>创建数据目录：</p>
<pre><code class="language-bash">mkdir -p /var/lib/kafka/logs
chown -R $(whoami):$(whoami) /var/lib/kafka
</code></pre>
<h4 id="systemd">创建Systemd服务</h4>
<p>ZooKeeper服务文件<code>/etc/systemd/system/zookeeper.service</code>：</p>
<pre><code class="language-ini">[Unit]
Description=Apache ZooKeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=kafka
ExecStart=/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target
</code></pre>
<p>Kafka服务文件<code>/etc/systemd/system/kafka.service</code>：</p>
<pre><code class="language-ini">[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service
After=zookeeper.service

[Service]
Type=simple
User=kafka
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target
</code></pre>
<p>创建专用用户并设置权限：</p>
<pre><code class="language-bash">useradd -r -d /opt/kafka -s /bin/nologin kafka
chown -R kafka:kafka /opt/kafka
chown -R kafka:kafka /var/lib/kafka
</code></pre>
<h4 id="kafka_2">启动Kafka服务</h4>
<pre><code class="language-bash"># 重新加载systemd
systemctl daemon-reload

# 启动ZooKeeper
systemctl start zookeeper
systemctl enable zookeeper

# 启动Kafka
systemctl start kafka
systemctl enable kafka

# 检查状态
systemctl status zookeeper
systemctl status kafka
</code></pre>
<h3 id="_19">集群部署</h3>
<h4 id="_20">准备工作</h4>
<p>在所有节点上安装Kafka，并针对每个节点修改配置。</p>
<h4 id="zookeeper">配置ZooKeeper集群</h4>
<p>在所有ZooKeeper节点上创建<code>/opt/kafka/config/zookeeper.properties</code>：</p>
<pre><code class="language-properties"># 基本配置
dataDir=/var/lib/zookeeper
clientPort=2181
maxClientCnxns=0

# 集群配置
initLimit=5
syncLimit=2
tickTime=2000

# 服务器列表
server.1=zk1:2888:3888
server.2=zk2:2888:3888
server.3=zk3:2888:3888
</code></pre>
<p>在每个ZooKeeper节点上创建myid文件:</p>
<pre><code class="language-bash"># 在服务器zk1上
echo &quot;1&quot; &gt; /var/lib/zookeeper/myid

# 在服务器zk2上
echo &quot;2&quot; &gt; /var/lib/zookeeper/myid

# 在服务器zk3上
echo &quot;3&quot; &gt; /var/lib/zookeeper/myid
</code></pre>
<h4 id="kafka_3">配置Kafka集群</h4>
<p>在每个Kafka节点上编辑<code>/opt/kafka/config/server.properties</code>：</p>
<p>第一个节点(kafka1)：</p>
<pre><code class="language-properties">broker.id=1
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://kafka1:9092
log.dirs=/var/lib/kafka/logs
zookeeper.connect=zk1:2181,zk2:2181,zk3:2181
</code></pre>
<p>第二个节点(kafka2)：</p>
<pre><code class="language-properties">broker.id=2
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://kafka2:9092
log.dirs=/var/lib/kafka/logs
zookeeper.connect=zk1:2181,zk2:2181,zk3:2181
</code></pre>
<p>第三个节点(kafka3)：</p>
<pre><code class="language-properties">broker.id=3
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://kafka3:9092
log.dirs=/var/lib/kafka/logs
zookeeper.connect=zk1:2181,zk2:2181,zk3:2181
</code></pre>
<h4 id="_21">启动集群</h4>
<p>在所有ZooKeeper节点上：</p>
<pre><code class="language-bash">systemctl start zookeeper
systemctl enable zookeeper
</code></pre>
<p>在所有Kafka节点上：</p>
<pre><code class="language-bash">systemctl start kafka
systemctl enable kafka
</code></pre>
<h3 id="_22">常见管理操作</h3>
<h4 id="_23">主题管理</h4>
<pre><code class="language-bash"># 创建主题
/opt/kafka/bin/kafka-topics.sh --create --bootstrap-server kafka1:9092 --replication-factor 3 --partitions 3 --topic my-topic

# 列出所有主题
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server kafka1:9092

# 查看主题详情
/opt/kafka/bin/kafka-topics.sh --describe --bootstrap-server kafka1:9092 --topic my-topic

# 删除主题
/opt/kafka/bin/kafka-topics.sh --delete --bootstrap-server kafka1:9092 --topic my-topic
</code></pre>
<h4 id="_24">消息生产和消费</h4>
<pre><code class="language-bash"># 生产消息
/opt/kafka/bin/kafka-console-producer.sh --broker-list kafka1:9092 --topic my-topic

# 消费消息(从头开始)
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka1:9092 --topic my-topic --from-beginning

# 消费消息(实时)
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka1:9092 --topic my-topic
</code></pre>
<h4 id="_25">消费者组管理</h4>
<pre><code class="language-bash"># 列出所有消费者组
/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server kafka1:9092 --list

# 查看消费者组详情
/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server kafka1:9092 --describe --group my-group

# 重置消费者组偏移量(到最早消息)
/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server kafka1:9092 --group my-group --reset-offsets --to-earliest --execute --topic my-topic
</code></pre>
<h3 id="_26">安全配置</h3>
<h4 id="saslscram">SASL/SCRAM认证</h4>
<ol>
<li>创建JAAS配置文件<code>/opt/kafka/config/kafka_server_jaas.conf</code>：</li>
</ol>
<pre><code>KafkaServer {
   org.apache.kafka.common.security.scram.ScramLoginModule required
   username=&quot;admin&quot;
   password=&quot;admin-secret&quot;;
};
</code></pre>
<ol>
<li>更新<code>/opt/kafka/config/server.properties</code>：</li>
</ol>
<pre><code class="language-properties"># 启用SASL_PLAINTEXT监听器
listeners=SASL_PLAINTEXT://:9092
advertised.listeners=SASL_PLAINTEXT://kafka1:9092
security.inter.broker.protocol=SASL_PLAINTEXT

# 配置SASL
sasl.enabled.mechanisms=SCRAM-SHA-256
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
</code></pre>
<ol>
<li>更新启动脚本以包含JAAS配置：</li>
</ol>
<p>在<code>/etc/systemd/system/kafka.service</code>文件的<code>[Service]</code>部分添加：</p>
<pre><code class="language-ini">Environment=&quot;KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_server_jaas.conf&quot;
</code></pre>
<ol>
<li>创建用户：</li>
</ol>
<pre><code class="language-bash">/opt/kafka/bin/kafka-configs.sh --zookeeper zk1:2181 --alter --add-config 'SCRAM-SHA-256=[password=user-secret],SCRAM-SHA-512=[password=user-secret]' --entity-type users --entity-name user
</code></pre>
<h3 id="kafka_4">监控Kafka</h3>
<h4 id="jmxprometheus">使用JMX和Prometheus</h4>
<ol>
<li>在<code>/etc/systemd/system/kafka.service</code>文件的<code>[Service]</code>部分添加：</li>
</ol>
<pre><code class="language-ini">Environment=&quot;KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false&quot;
</code></pre>
<ol>
<li>安装JMX Exporter并配置Prometheus以抓取JMX指标。</li>
</ol>
<h2 id="redis-pubsub">Redis Pub/Sub</h2>
<p>Redis Pub/Sub是一种轻量级的消息传递模式，用于构建简单的消息系统。虽然不是专门的消息队列，但Redis提供了基本的发布/订阅功能。</p>
<h3 id="redis">Redis 安装与配置</h3>
<h4 id="redis_1">安装Redis</h4>
<pre><code class="language-bash"># CentOS/RHEL
yum install -y epel-release
yum install -y redis

# Debian/Ubuntu
apt-get update
apt-get install -y redis-server
</code></pre>
<h4 id="redis_2">配置Redis</h4>
<p>编辑<code>/etc/redis/redis.conf</code>：</p>
<pre><code># 基本配置
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log

# 性能相关
databases 16
maxclients 10000
</code></pre>
<h4 id="redis_3">启动Redis服务</h4>
<pre><code class="language-bash"># 启动Redis
systemctl start redis
systemctl enable redis
systemctl status redis
</code></pre>
<h3 id="redis-pubsub_1">使用Redis Pub/Sub</h3>
<h4 id="_27">基本命令</h4>
<pre><code class="language-bash"># 发布消息
redis-cli PUBLISH channel1 &quot;Hello World&quot;

# 订阅频道
redis-cli SUBSCRIBE channel1

# 订阅多个频道
redis-cli SUBSCRIBE channel1 channel2

# 基于模式订阅
redis-cli PSUBSCRIBE channel*

# 取消订阅
redis-cli UNSUBSCRIBE channel1
redis-cli PUNSUBSCRIBE channel*
</code></pre>
<h4 id="_28">消息持久化</h4>
<p>Redis Pub/Sub默认不持久化消息。如需持久化，可以结合Redis Stream:</p>
<pre><code class="language-bash"># 添加消息到Stream
redis-cli XADD mystream * sensor-id 1234 temperature 19.8

# 从Stream读取消息
redis-cli XREAD COUNT 2 STREAMS mystream 0

# 创建消费者组
redis-cli XGROUP CREATE mystream mygroup 0

# 组消费消息
redis-cli XREADGROUP GROUP mygroup consumer1 COUNT 1 STREAMS mystream &gt;
</code></pre>
<h4 id="_29">客户端示例</h4>
<p>Python示例:</p>
<pre><code class="language-python">import redis

# 连接Redis
r = redis.Redis(host='localhost', port=6379, db=0)

# 发布消息
r.publish('channel1', 'Hello World')

# 订阅者
pubsub = r.pubsub()
pubsub.subscribe('channel1')

# 监听消息
for message in pubsub.listen():
    if message['type'] == 'message':
        print(f&quot;Received: {message['data']}&quot;)
</code></pre>
<h2 id="_30">后续章节</h2>
<p>本文档的后续部分将介绍更多消息队列和中间件系统，包括：</p>
<ul>
<li>ActiveMQ：传统企业级消息代理</li>
<li>ZeroMQ：轻量级的嵌入式消息库</li>
<li>NSQ：实时分布式消息平台</li>
<li>NATS：云原生消息系统</li>
<li>Amazon SQS与SNS：云托管消息服务</li>
</ul>
<p>请参考各部分的详细文档获取完整的部署和配置指南。</p>












                
              </article>
            </div>
          
          
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
        <div class="md-social">
  
    
    
    
    
      
      
    
    <a href="https://git.opsx.vip/docs/PythonFullStackGuide.git" target="_blank" rel="noopener" title="git.opsx.vip" class="md-social__link">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8M97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg>
    </a>
  
    
    
    
    
    <a href="mailto:admin@attacker.club" target="_blank" rel="noopener" title="" class="md-social__link">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4l217.6 163.2c11.4 8.5 27 8.5 38.4 0l217.6-163.2c12.1-9.1 19.2-23.3 19.2-38.4 0-26.5-21.5-48-48-48zM0 176v208c0 35.3 28.7 64 64 64h384c35.3 0 64-28.7 64-64V176L294.4 339.2a63.9 63.9 0 0 1-76.8 0z"/></svg>
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    
    <script id="__config" type="application/json">{"base": "../..", "features": [], "search": "../../assets/javascripts/workers/search.f8cc74c7.min.js", "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}}</script>
    
    
      <script src="../../assets/javascripts/bundle.60a45f97.min.js"></script>
      
        <script src="../../js/prism.js"></script>
      
    
  </body>
</html>